package JVM;

public class a1b2_2 {
    static Thread t1=null,t2=null;

    public static void main(String[] args) {
        char[] c1={'a','b','c','d','e','f'};
        char[] c2="12345".toCharArray();
        Object o=new Object();
        t1=new Thread(()->{
            synchronized (o){
                for (int i=0;i<c1.length;i++){
                    System.out.println(c1[i]);
                    try {
                        o.notify();  //注意  这里调的是o的方法，不是线程的方法
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify(); //必须要加上 否则会程序不可以终止
            }
        });
        t2=new Thread(()->{
            synchronized (o){
                for (int i=0;i<c2.length;i++){
                    System.out.println(c2[i]);
                    try {
                        o.notify();
                        o.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                o.notify();
            }
        });
        t1.start();
        t2.start();
    }
}
